home *** CD-ROM | disk | FTP | other *** search
/ Windows News 2010 Summer - Disc 1 / WN_Ete2010_CD1.iso / Onglet5 / Weezo / Weezo setup.exe / {code_appDir} / www / ping.php < prev    next >
PHP Script  |  2010-05-19  |  5KB  |  124 lines

  1. <?php
  2. /**
  3.  * Ping script
  4.  * Script periodically "async" called by menuFrame.php to inform server that user is still connected
  5.  * return empty XML response file
  6.  *
  7.  * PHP version 5
  8.  *
  9.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  10.  * that is available through the world-wide-web at the following URI:
  11.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  12.  * the PHP License and are unable to obtain it through the web, please
  13.  * send a note to license@php.net so we can mail you a copy immediately.
  14.  *
  15.  * @category   NA
  16.  * @package    NA
  17.  * @author     Nicolas Bruley / Peer 2 World <contact@weezo.net>
  18.  * @copyright  2005-2009 Nicolas Bruley / Peer 2 World
  19.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  20.  * @version    CVS: $Id:$
  21.  * @link       http://www.weezo.net
  22.  * @since      File available since Release 1.0.0
  23.  */
  24.  
  25.  
  26.  
  27. //cfDebugSingle('PING '.$_SERVER['HTTP_USER_AGENT']);
  28.  
  29. // Ping server
  30. if(isset($_GET['checkServer'])){
  31.     $output='serverOnline';
  32.     // Check secret key
  33.     if(!customIssetKey()) $output.='keyNotSet';
  34.     // Ping BitTorrent seeder ($_GET['checkSeeder'] is bittorrent seeder port number)
  35.     if(isset($_GET['checkSeeder']) && is_numeric($_GET['checkSeeder'])){
  36.  
  37.         // Set info that seeder is being checked so debug info is not displayed by seeder
  38.         cfMSetVar('checkingSeeder',time());
  39.  
  40.         // Open a connection on seeder to see if it's responding
  41.         if($sock=@fsockopen('127.0.0.1',$_GET['checkSeeder'],$errno,$errstr,3)){
  42.             fclose($sock);
  43.             $output.='seederOnline';
  44.         }
  45.         else $output.='seederOffline';
  46.     }
  47.     // Clear APC cache
  48.     if(function_exists('apc_cache_info')){
  49.         $cl=@apc_cache_info();
  50.         $latest=0;
  51.         if(isset($cl['cache_list'])){
  52.             // Check for last access time (except ping scripts)
  53.             foreach ($cl['cache_list'] as $v){
  54.                 $bn=basename($v['filename']);
  55.                 if($bn!='ping.php' && $bn!='security.php' && $bn!='commonFunctions.php' && $bn!='bittorrentSeeder.php' && $bn!='test.php' && $v['access_time']>$latest) $latest=$v['access_time'];
  56.             }
  57.             // If last access time older than APCTTL, clear cache
  58.             if($latest>0 && cfGGetVar('APCTTL') && is_numeric(cfGGetVar('APCTTL')) && (time()-$latest)>cfGGetVar('APCTTL'))
  59.                 apc_clear_cache();
  60.         }
  61.     }
  62.     echo $output;
  63.     exit;
  64. }
  65. // External server access test
  66. elseif(isset($_GET['check'])) die('<ping>ok:'.cfGGetVar('LANIPComputed').'</ping>');
  67.  
  68. // Wake on Wan test
  69. elseif(isset($_GET['wow'])) die('<script type="text/javascript">parent.connected()</script>');
  70.  
  71. // Image used to detect that computer is awakened and server responding, after wake-up command sent
  72. elseif(isset($_GET['wowImg'])) {
  73.     header('P3P: policyref="/w3c/p3p.xml",CP="NON COR CURa OUR NOR NAV"');
  74.     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  75.     header('Content-type: image/gif');
  76.     imagegif(imagecreate(1,50));
  77.     exit;
  78. }
  79.  
  80. // If session file doesn't exist anymore (destroyed on server), inform user that he has been logged out
  81. if(!isset($_COOKIE["WSESSID"]) ||
  82. (cfGGetVar('sessionHandler')=='memory' && !cfMIssetVar('weezoSess_'.$_COOKIE["WSESSID"])) ||
  83. !file_exists(cfAppDataDir().'/sessiondata/sess_'.$_COOKIE["WSESSID"])){
  84.     // Response XML header
  85.     cfAsyncHeader();
  86.     // Inform user
  87.     echo cfAsyncXMLJSaction('if(W.pingInt) clearInterval(pingInt)');
  88.     // Stop pinging
  89.     echo cfAsyncXMLJSaction('if(!W.disconnectionSent) {disconnectionSent=1;alert("'.cfCaption('logUserLogout').' '.@strftime('%Hh %Mm %Ss', mktime()).'");};if(parent) parent.location.href="/index.php"; else location.href="/index.php";');
  90.     echo cfAsyncFooter();
  91.  
  92.     // Make sure memory and files are cleared
  93.     if(isset($_COOKIE["WSESSID"])){
  94.         if(cfGGetVar('sessionHandler')=='memory' && cfMIssetVar('weezoSess_'.$_COOKIE["WSESSID"])) cfMUnsetVar('weezoSess_'.$_COOKIE["WSESSID"]);
  95.         if(file_exists(cfAppDataDir().'/sessiondata/sess_'.$_COOKIE["WSESSID"])) @unlink(cfAppDataDir().'/sessiondata/sess_'.$_COOKIE["WSESSID"]);
  96.     }
  97.     exit();
  98. }
  99.  
  100. // Inform application
  101. $res=cfPingUpdate();
  102. // Check if a resource force-open is required by server
  103. if(cfMIssetVar('weezoChatForceOpen'.$_COOKIE["WSESSID"])){
  104.     wSession_start();
  105.     // Response XML header
  106.     cfAsyncHeader();
  107.  
  108.     foreach(cfResourcesGetUser() as $id=>$value){
  109.         if($value['resourceName'].'.res'==cfMGetVar('weezoChatForceOpen'.$_COOKIE["WSESSID"])){
  110.             if(cfTGetVar('frames')) echo cfAsyncXMLJSaction($value['resourceJsLink']);
  111.             else echo cfAsyncXMLJSaction('document.location="/res/'.$value['type'].'/'.$value['subType'].'/'.$value['baseFile']);
  112.         }
  113.     }
  114.     cfMUnsetVar('weezoChatForceOpen'.$_COOKIE["WSESSID"]);
  115. }
  116. else {
  117.     // Response XML header
  118.     cfAsyncHeader();
  119. }
  120. // If server connection failed, send warning to browser
  121. if($res===NULL) echo cfAsyncXMLJSaction('if(dgi(\'rSPb\')) dgi(\'rSPb\').style.display="block";dgi(\'rSPb\').innerHTML="App. not resp.:'.strftime('%Hh %Mm %Ss', mktime()).'";');
  122. // All OK: hide alert div
  123. else echo cfAsyncXMLJSaction('if(dgi(\'rSPb\')) dgi(\'rSPb\').style.display="none"');
  124. echo cfAsyncFooter();